<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;


class AnswerController extends Controller
{
    //查看答案
    public function getCheck(Request $request,$question_id)
    {
        //每页显示条数
        $num=$request->input('num',10);
        // dd($question_id);
        // dd($num);
        //判断是否有关键字
        if($request->input('keywords'))
        {
            //按照有关键字查询
            $res=DB::table('answer')
                ->where('answer_content','like','%'.$request->input('keywords').'%')
                ->where('question_id',$question_id)
                ->paginate($num);
        }else
        {
            //没有的话全查询
            $res=DB::table('answer')->where('question_id',$question_id)->paginate($num);
        } 


        //带着关键字翻页,分配参数
        $data=$request->all();
        // $res['question_id']=$question_id;
        // dd($res);
        // dd($data);

        //解析答案的回答的模板
        return view('Admin.answer.list',['answers'=>$res,'data'=>$data]);
    }

    //删除答案
    public function getDelete($id)
    {
        $res=DB::table('answer')->where('id',$id)->delete();
        if($res)
        {
            return back()->with('success','删除成功');
        }else
        {
            return back()->with('error','删除失败');
        }
    }
    
}
